package com.koron.operation.classes.form.bean.vo;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.koron.operation.classes.form.bean.constants.ClassesFormUtil;
import com.koron.operation.classes.form.bean.po.ClassesFormShift;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

/**
 * @author jzp
 * @since 2023/5/19
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel(value = "月度排班打卡记录列表", description = "ClassesFormRecordVO")
public class ClassesFormRecordVO extends ClassesFormShift {

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("上班时间")
    private Date startTime;

    /**
     * 值班结束时间
     */
    @ApiModelProperty("下班时间")
    private Date endTime;

    @ApiModelProperty("上班时长(h)")
    private String duration;

    @ApiModelProperty("值班单位id")
    private String deptId;

    /**
     * 值班单位名称
     */
    @ApiModelProperty("值班单位名称")
    private String deptName;

    public String getDuration() {
        if (startTime == null || endTime == null || startTime.after(endTime)) {
            return null;
        }
        return ClassesFormUtil.betweenHour(startTime, endTime);
    }

    public String getRemark() {
        if (StrUtil.isEmpty(remark)) {
            return null;
        }
        String[] remarkArr = ArrayUtil.removeBlank(remark.split("/@/"));

        StringBuilder result = new StringBuilder();
        if (remarkArr.length == 1) {
            return remarkArr[0];
        }
        for (String s : remarkArr) {
            result.append("- ").append(s).append("\n");
        }
        return result.toString();
    }
}
